<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>错误！</strong>
	无效的收款信息！
</div>
<#else>
<form class="contract-payin-change-form" action="${request.contextPath}/contract/payin-plan-change" method="post">
	<input type="hidden" name="id" value="${data.id}" />
	<input type="hidden" name="changed" value="true" />
	<input type="hidden" name="contract.id" value="${cid}" />
	<input type="hidden" name="createTime" value="${(data.createTime?string('yyyy-MM-dd'))!''}" />
	<input type="hidden" name="back" value="false" />
	<input type="hidden" name="creater.id" value="${data.creater.id}" />
	<input type="hidden" name="remark" value="${data.remark}" />
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款单位
						</div>
					</div>
					<input type="text" class="form-control not-empty" name="moneyFrom" value="${data.moneyFrom}" placeholder="最多100个汉字" />
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款事项
						</div>
					</div>
					<textarea rows="5" class="form-control not-empty" name="reason" placeholder="最多300个中文">${data.reason}</textarea>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款负责人
						</div>
					</div>
					<select class="form-control not-empty" name="header.id">
						<#if header??> <#list header as h>
						<option value="${h.id}" ${((data.header.id==h.id)?string('selected',''))!''}>${h.name}</option>
						</#list> </#if>
					</select>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款金额
						</div>
					</div>
					<input type="text" class="form-control not-empty number" name="total" value="${data.total}" placeholder="请输入收款金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" data-format="yyyy-MM-dd" data-foot="false" name="backTime" value="${(data.backTime?string('yyyy-MM-dd'))!''}" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							变更原因
						</div>
					</div>
					<textarea rows="5" class="form-control not-empty" name="changeReason" placeholder="最多1000个中文"></textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		$('form.contract-payin-change-form .btn-submit').on('click', function() {
			var form = $('form.contract-payin-change-form');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);
			var okBtn = $('form.contract-payin-change-form .btn-submit');

			if (okBtn.hasClass('disabled'))
				return false;

			okBtn.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '变更收款计划信息失败!');
						okBtn.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${cid}', [ 'div#tab5' ]);

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('变更收款计划信息失败!\n' + errorThrown);
					okBtn.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
